package com.reggie.module.entity.dto.categoryDto;

import com.reggie.module.entity.po.Category;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

import static com.reggie.common.Constant.LOGIN_SESSION;

/**
 * @Author 早睡蛋
 * @Date 2022/9/21 16:21:48
 * @Desc:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddCategoryDto {

    @NotNull(message = "分类不能为空")
    //类型 1 菜品分类 2 套餐分类
    private Integer type;

    @NotEmpty(message = "分类名称不能为空")
    //分类名称
    private String name;

    //顺序
    private Integer sort;


    public Category add(HttpServletRequest request){
        Category category = new Category();
        category.setType(this.type);
        category.setName(this.name);
        category.setSort(this.sort);
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        Long empId = (Long) request.getSession().getAttribute(LOGIN_SESSION);
        category.setCreateUser(empId);
        category.setUpdateUser(empId);
        return category;
    }

}
